package com.xiaoyu.lanling.feature.login.data

import com.ishumei.smantifraud.SmAntiFraud
import com.xiaoyu.base.config.HttpConfig
import com.xiaoyu.base.data.UserData
import com.xiaoyu.base.net.RequestCreator
import com.xiaoyu.lanling.event.login.*

object LoginData {

    fun loginRegSms(requestTag: Any, cellphone: String) {
        RequestCreator.create<LoginRegSmsEvent>(requestTag, LoginRegSmsEvent::class.java)
                .setRequestUrl(HttpConfig.APP_LOGIN_REG_SMS)
                .setPostEventWhenFail(true)
                .addQueryData("cellphone", cellphone)
                .enqueue()
    }

    fun login(requestTag: Any, cellphone: String, code: String) {
        RequestCreator.create<LoginEvent>(requestTag, LoginEvent::class.java)
                .setRequestUrl(com.xiaoyu.lanling.common.config.HttpConfig.LANLING_LOGIN)
                .addQueryData("cellphone", cellphone)
                .addQueryData("code", code)
                .addQueryData("deviceId", SmAntiFraud.getDeviceId())
                .enqueue()
    }

    fun logout(requestTag: Any) {
        RequestCreator.create<LogoutEvent>(requestTag, LogoutEvent::class.java)
                .setRequestUrl(com.xiaoyu.lanling.common.config.HttpConfig.LANLING_LOGOUT)
                .addPostData("refreshToken", UserData.getInstance().tokenInfo.refreshToken)
                .addPostData("accessToken", UserData.getInstance().tokenInfo.accessToken)
                .enqueue()
    }

    fun lockMessage(requestTag: Any, cellphone: String, openId: String) {
        RequestCreator.create<LockMessageEvent>(requestTag, LockMessageEvent::class.java)
                .setRequestUrl(HttpConfig.USER_LOCK_MESSAGE)
                .addQueryData("cellphone", cellphone)
                .addQueryData("openId", openId)
                .enqueue()
    }

    fun wechatLogin(requestTag: Any, wechatAuthCode: String) {
        RequestCreator.create<WechatLoginEvent>(requestTag, WechatLoginEvent::class.java)
                .setRequestUrl(com.xiaoyu.lanling.common.config.HttpConfig.LANLING_WECHAT_LOGIN)
                .setPostEventWhenFail(true)
                .addQueryData("wechatAuthCode", wechatAuthCode)
                .addQueryData("deviceId", SmAntiFraud.getDeviceId())
                .enqueue()
    }
}